package view.model;

import java.util.ArrayList;

import javax.swing.event.TableModelListener;
import javax.swing.table.TableModel;

import entity.User;
import service.user.UserService;
import service.user.UserServiceImpl;


/**
 * @Author: Lin Hongwei
 * @LastEditors: Lin Hongwei
 * @email: 1365755396@qq.com
 * @CSDN: https://blog.csdn.net/weixin_45429409
 * @Description: 定义用户信息表格公用显示模板
 *
 */
public class UserTableModel implements TableModel {
	String[] columnNames = {"用户id","用户名称","用户角色","用户身份"};
	private static UserService userServiceImpl = new UserServiceImpl();
	public static ArrayList<User> userList= (ArrayList<User>) userServiceImpl.getUserList(null) ;
	
	
	@Override
	public void addTableModelListener(TableModelListener arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public Class<?> getColumnClass(int arg0) {
		// TODO Auto-generated method stub
		return String.class;
	}

	@Override
	public int getColumnCount() {
		// TODO Auto-generated method stub
		return columnNames.length;
	}

	@Override
	public String getColumnName(int index) {
		// TODO Auto-generated method stub
		return columnNames[index];
	}

	@Override
	public int getRowCount() {
		// TODO Auto-generated method stub
		return userList.size();
	}

	@Override
	public Object getValueAt(int rowIndex, int columnIndex) {
		// TODO Auto-generated method stub
		
		User user = userList.get(rowIndex);//获取到选择一行数据
		switch(columnIndex) {
		   case 0:
			   return user.getId();
		   case 1:
			   return user.getUserName();
		   case 2:
			   return user.getAdmin()==1?"管理员":"读者";
		   case 3:
			   return user.getType();
		}
		
		return null;
	}

	@Override
	public boolean isCellEditable(int arg0, int arg1) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public void removeTableModelListener(TableModelListener arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void setValueAt(Object arg0, int arg1, int arg2) {
		// TODO Auto-generated method stub
		
	}

}
